package com.chandon.T05_timeApi.T01_temporal;

import java.time.LocalTime;
import java.time.temporal.ChronoField;

/**
 * 描述
 *
 * @author Dong
 * @version 1.0
 * @date 2021-04-27 1:08
 */

public class T03_LocalTimeTest {
    public static void main(String[] args) {

//        staticTest();

//        getAndGetLong();

        LocalTime now = LocalTime.now();

        // 增加时间单位
        LocalTime plusHours = now.plusHours(1);
        LocalTime plusMinutes = now.plusMinutes(10);
        LocalTime plusSeconds = now.plusSeconds(10);

        // 减少时间单位
        LocalTime minusHours = now.minusHours(1);
        LocalTime minusMinutes = now.minusMinutes(1);
        LocalTime minusSeconds = now.minusSeconds(1);

        System.out.println(plusHours);
        System.out.println(plusMinutes);
        System.out.println(plusSeconds);
        System.out.println(minusHours);
        System.out.println(minusMinutes);
        System.out.println(minusSeconds);

        System.out.println("------------------");

        // localtime转换一天中对应的秒、纳秒
        int secondOfDay = now.toSecondOfDay();
        long nanoOfDay = now.toNanoOfDay();
        System.out.println(secondOfDay);
        System.out.println(nanoOfDay);



    }

    private static void getAndGetLong() {
    /*
        int get()
        Long getLong()
        返回LocalTime所支持的时间度量，isSupported(ChronoFiled filed)
        NANO_OF_SECOND
        NANO_OF_DAY
        MICRO_OF_SECOND
        MICRO_OF_DAY
        MILLI_OF_SECOND
        MILLI_OF_DAY
        SECOND_OF_MINUTE
        SECOND_OF_DAY
        MINUTE_OF_HOUR
        MINUTE_OF_DAY
        HOUR_OF_AMPM
        CLOCK_HOUR_OF_AMPM
        HOUR_OF_DAY
        CLOCK_HOUR_OF_DAY
        AMPM_OF_DAY

     */
        LocalTime localTime = LocalTime.now();

        // 获取localtime对应的时间度量如：所在一天中的秒数，小时数
        long second = localTime.getLong(ChronoField.SECOND_OF_DAY);
        long hours = localTime.getLong(ChronoField.HOUR_OF_DAY);
        long instantSecond = localTime.getLong(ChronoField.HOUR_OF_DAY);
        System.out.println(second);
        System.out.println(hours);
        System.out.println(instantSecond);

        // 0-上午 1-下午
        long hourss = localTime.getLong(ChronoField.AMPM_OF_DAY);
        System.out.println(hourss);

        // 一分钟的第几秒
        long epochDay = localTime.getLong(ChronoField.SECOND_OF_MINUTE);

        System.out.println(epochDay);
    }

    private static void staticTest() {
        // 当前时间
        LocalTime now = LocalTime.now();
        System.out.println(now);//01:11:16.617
        // 时分秒纳秒
        System.out.println(now.getHour());
        System.out.println(now.getMinute());
        System.out.println(now.getSecond());

        // 时间构造
        LocalTime time = LocalTime.of(14, 11);
        LocalTime timeSecond = LocalTime.of(14, 11,13);
        System.out.println(time);
        System.out.println(timeSecond);

        // 一天中的秒数对应的LocalTime
        LocalTime secondOfDay = LocalTime.ofSecondOfDay(10);
        System.out.println(secondOfDay);

        // 字符串时间解析
        LocalTime localTime = LocalTime.parse("10:11");
        System.out.println(localTime);
    }

}
